<template>
  <div class="search-result-container">
    <!-- 点击实现后退效果 -->
    <van-nav-bar
      title="搜索结果"
      left-arrow
      @click-left="$router.go(-1)"
      fixed
    />

<van-list
  v-model="loading"
  :finished="finished"
  finished-text="没有更多了"
  @load="onLoad"
  offset="50"
  :immediate-check="false"

>
 <ArtileItem :obj="item" v-for="item in searchresultlist"
 :key="item.art_id"
 :iscrossshow="false"></ArtileItem>
</van-list>

  </div>
</template>

<script>
import ArtileItem from '@/components/ArtileItem'
import { getSearchResultAPI } from '@/api'
import { getTime } from '@/utils/datetime.js'
export default {
  name: 'SearchResult',
  components: {
    ArtileItem
  },
  data () {
    return {
      searchresultlist: [], // 搜索结果列表
      page: 1, // 页面
      loading: false,
      finished: false
    }
  },
  created () {
    this.getsearchresultlist()
  },
  methods: {
    getTime,
    async getsearchresultlist () {
      const q = this.$route.params.keywords
      const res = await getSearchResultAPI({ q: q, page: this.page })
      if (res.data.data.results === 0) {
        this.finished = true
        return
      }
      res.data.data.results.forEach((obj) => {
        obj.pubdate = this.getTime(obj.pubdate)
      })
      this.searchresultlist = [...this.searchresultlist, ...res.data.data.results]
      this.loading = false
    },
    onLoad () {
      this.page++
      this.getsearchresultlist()
    }
  }
//
}
</script>

<style lang="less" scoped>
.search-result-container {
  padding-top: 46px;
}
</style>
